'use strict';

let gradeIndex = 0

let subjectIndex = 0

let result = {}

const GetEl = (cls, parent) => (parent || document.body).querySelector(cls)

const GetList = (cls, parent) => (parent || document.body).querySelectorAll(cls)

const prevHooks = () => {
    const subject = GetEl('.subject-nav-base')
    subject.style.display = 'block'
    subject.children[gradeIndex].querySelector('.grade-item__list').children[subjectIndex].click()
}

const loop = (el, i) => {
    const key = el.children[0].querySelector('a').textContent
    const ul = GetEl('.tree-ul', el)
    if (!ul) return ({[i]: key})
    return ({[key]: ul.map((item, i) => loop(item, i))})
}

const handler = () => {
    const list = GetEl('.tree-top-ul')
    const data = list.map((item, i) => loop(item, i))
    console.log(data)
}

prevHooks()
handler()
